<?php
/**
 * Created by PhpStorm.
 * User: zhouliang
 * Date: 2021/2/27
 * Time: 上午10:39
 */

namespace App\Traits;

trait AdminLog
{
    public function addAdminLog($log_info)
    {
        $request = app("request");
        $action = $request->route()[1]['uses'];

        [$class, $method] = explode('@', $action);
        $controller = substr(strrchr($class, '\\'), 1);

        $data['admin_id'] = $request->admin_id;
        $data['client_ip'] = $request->getClientIp();
        $data['dateline'] = time();
        $data['uri'] = $request->path();;
        $data['action_name'] = $controller;
        $data['method_name'] = $method;
        $data['content'] = $log_info;

        app("model_admin_log")->create($data);
    }
}
